#ifndef __WIN_LOGO_H__
#define __WIN_LOGO_H__

#include <iostream>

#define CHESS_BOARD_WIDTH 57
#define CHESS_BOARD_HEIGHT 29
#define X_OFFSET 3

using namespace std;

class WinLogo
{
public:
	WinLogo(int x = 0, int y = 0, int width = 25, int height = 15)
	{
		this->width = width;
		this->height = height;

		if (!x)
		{
			this->x = CHESS_BOARD_WIDTH + X_OFFSET;
		}
		else
		{
			this->x = x;
		}

		if (!y)
		{
			this->y = (CHESS_BOARD_HEIGHT - height) / 2;
		}
		else
		{
			this->y = y;
		}
	}

	void drawRectangle(int x, int y, int width, int height, int color)
	{
		fprintf(stderr, "\033[%d;%dH", y, x);
		for (int i = 0; i < height; i++)
		{
			for (int j = 0; j < width; j++)
			{
				fprintf(stderr, "\033[%dm \033[0m", color);
			}
			fprintf(stderr, "\033[%d;%dH", y + i, x);
		}
	}

	void drawText(int x, int y, const char* text, int bgColor, int fColor)
	{
		fprintf(stderr, "\033[%d;%dH\033[%d;%dm%s\033[0m", y, x, bgColor, fColor, text);
	}

	void showWinPlayer(const string& name, const string& color)
	{
		drawRectangle(x, y, width, height, 42);
		drawRectangle(x + 2, y + 1, width, height, 47);

		string colorText = "The color is ";
		colorText += color;
		drawText(x + 3, y + 1 + height / 2 - 2, colorText.c_str(), 47, 33);

		string winnerText = "The winner is ";
		winnerText += name;
		drawText(x + 3, y + 2 + height / 2 - 2, winnerText.c_str(), 47, 34);

		drawText(x + 3, y + 3 + height / 2 - 2, "Made by GuguLH.", 47, 35);
	}

private:
	int x;
	int y;
	int width;
	int height;
};

#endif // !__WIN_LOGO_H__
